package com.idol.controller;

import com.idol.annotation.Autowired;
import com.idol.factory.BeanContainer;

import javax.servlet.http.HttpServlet;
import java.lang.reflect.Field;

/**
 * @author Supreme_Sir
 * @version 1.0
 * @className MyHttpServlet
 * @description
 * @date 2020/10/14 0:18
 **/
public class MyHttpServlet extends HttpServlet {
    @Override
    public void init() {
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            if (field.isAnnotationPresent(Autowired.class)) {
                field.setAccessible(true);
                try {
                    field.set(this, BeanContainer.getBeanContainer().get(field.getType().toString().split(" ")[1]));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
